package com.example.design.demo.single;

/**
 * @author lfj
 * @date 2023/11/10 18:25
 * 懒汉式(完美)
 * 1.声明一个静态内部类的对象声明
 *  JVM保证线程安全
 */
public class SingletonLazy04 {



    private SingletonLazy04(){};

    private static class  MySingletonLazy04{
        private static final SingletonLazy04 instance=new SingletonLazy04();
    }

    public static SingletonLazy04 getInstance(){

        return MySingletonLazy04.instance;

    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()-> {
                System.out.println(SingletonLazy04.getInstance().hashCode());
            }).start();
        }
    }
}


